#define _CRT_SECURE_NO_WARNINGS 1
#include "Queue.h"
void QueInit(Queue *pq) {
	pq->head = NULL;
	pq->lost = NULL;
	pq->size = 0;
}
void QueuePush(Queue* pq, Qtypedate x) {
	assert(pq);
	Qnode* newnode = (Qnode*)malloc(sizeof(Qnode));
	if (newnode == NULL)
	{
		perror("malloc:");
		return;
	}
	newnode->val = x;
	newnode->next = NULL;
	if (pq->head == NULL)
	{
		pq->head  = pq->lost = newnode;
	}
	else {
		pq->lost->next = newnode;
		pq->lost = newnode;
	}
	pq->size++;
}
void QueuePop(Queue* pq) {
	assert(pq);
	assert(pq->head);
	Qnode* del = pq->head;
	pq->head = pq->head->next;
	free(del);
	if (pq->head == NULL)
		pq->lost = NULL;
	pq->size--;
}
Qtypedate QueueFront(Queue* pq) {
	assert(pq);
	assert(pq->head);
	return pq->head->val;
}
Qtypedate QueueBack(Queue* pq) {
	assert(pq);
	assert(pq->lost);
	return pq->lost->val;
}
bool QueueEmpty(Queue* pq) {
	assert(pq);
	return pq->head == NULL;
}
int QueueSize(Queue* pq) {
	assert(pq);
	return pq->size;
}
void QueueDistory(Queue* pq) {
	assert(pq);
	while (pq->head)
	{
		Qnode* del = pq->head;
		pq->head = pq->head->next;
		free(del);
	}
	if (pq->head == NULL)
		pq->lost = NULL;
	pq->size = 0;
}